<?php
$v_current_af_id = '';
if(isset($_REQUEST['hdn_af_id'])){
	$v_current_af_id = $_REQUEST['hdn_af_id'];
}
//Luu nhung dieu kien loc hien thoi
//Cac chu cai loc
if(isset($_REQUEST['hdn_filter'])){
	$v_filter = $_REQUEST['hdn_filter'];
}else{	
	$v_filter = "";
}
//Linh vuc loc
if(isset($_REQUEST['hdn_back_cate_id']))
{
	$v_cate_id = $_REQUEST['hdn_back_cate_id'];
}
if(isset($_REQUEST['hdn_back_agency_id']))
{
	$v_agency_id = $_REQUEST['hdn_back_agency_id'];
}
if (isset($_REQUEST['hdn_method'])){
	$v_method = $_REQUEST['hdn_method'];
}
if (isset($_REQUEST['hdn_status']))
{
	$v_status = $_REQUEST['hdn_status'];
}
// Luu ten style hien thoi
$v_current_style_name = "odd_row";
// Luu ten style tiep theo
$v_next_style_name = "";
// Luu ten form
$v_form_name = "f_dsp_all_af";
$v_goto_url = "index.php";
?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="normal_title">
		<td>
			<?php echo CONST_AF_LIST_TITLE; ?>
			<a id="goto" href="" style=".color:white">#</a>
		</td>
	</tr>
</table>
<!-- bang chua cac tieu thuc loc-->
<table cellpadding="0" cellspacing="0" width="100%" >								
	<tr>
	 	<form action="index.php" name="<?php echo $v_form_name;?>" method="post">
		<input type="hidden" name="hdn_af_id"  value="<?php echo $v_af_id;?>">
		<input type="hidden" name="hdn_back_cate_id"  value="<?php echo $v_cate_id;?>">
		<input type="hidden" name="hdn_method" value="<?php echo $v_method;?>">
		<input type="hidden" name="hdn_back_agency_id"  value="<?php echo $v_agency_id;?>">
		<input type="hidden" name="hdn_status" valus="<?php echo $v_status;?>">
		<input type="hidden" name="hdn_list_af_id"  value="0">
		<input type="hidden" name="hdn_filter"  value="<?php echo $v_filter; ?>">
		<input type="hidden" name="fuseaction"  value="">
	</tr>
	<tr><td height="5"></td></tr>
</table>	
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<col width="25%"><col width="25%"><col width="25%"><col width="25%">
	<tr>
	    <td  colspan="4"class="normal_label" ><?php echo CONST_AF_AGENCY_LABEL;?>&nbsp;
			<select class= "normal_selectbox" style="width:90%"   name = "cbo_af_agency" onChange="get_id_from_selected(document.forms(0).cbo_af_agency,document.forms(0).hdn_back_agency_id);" optional = "<?php echo CONST_AF_AGENCY_OPTIONAL; ?>">
				<option id="-1",value="-1">--------<?php echo CONST_AF_AGENCY ?>--------</option>			
				<? echo _generate_select_option($arr_all_agency,"0","0","2", $v_agency_id);?>
			</select>
		</td>
	</tr>
	<tr><td colspan="4" height="5"></td></tr>
	<tr>
		<td  colspan="2" class="normal_label" align="left"><?php echo CONST_AF_CATE_LABEL;?>&nbsp;
			<select class= "normal_selectbox" style="width:75%"  name = "cbo_af_cate" onChange="get_id_from_selected(document.forms(0).cbo_af_cate,document.forms(0).hdn_back_cate_id);" optional = "<?php echo CONST_AF_CATE_OPTIONAL; ?>">
				<option id="-1",value="-1">--------<?php echo CONST_AF_CATE ?>--------</option>
				<? echo _generate_select_option($arr_all_cate,"0","0","2", $v_cate_id);?>	
			</select>
		</td>
		<td width="30%" class="normal_label"><?php echo CONST_AF_STATUS;?>&nbsp;&nbsp;
          <select class= "normal_selectbox"  style="width:78% "name = "cbo_status" onChange="get_id_from_selected(document.forms(0).cbo_status,document.forms(0).hdn_status);" optional = "<?php echo CONST_AF_STATUS_OPTIONAL; ?>">
            <option id="-1",value="-1">------------------<?php echo CONST_AF_STATUS_ALL ?>------------------</option>
            <? echo _generate_select_option($arr_all_status,"0","0","1", $v_status);?>
          </select>
		</td>
	</tr>
	<tr><td colspan="4" height="5"></td></tr>
	<tr>
		<td  colspan="2"class="normal_label"><?php echo CONST_AF_SEARCH_METHOD?>&nbsp;
			<input type="radio" name="rad_filter" class="normal_radiobutton" value="1" <?php if ($v_method == 1) echo 'checked';?> onclick="document.forms(0).hdn_method.value = 1;"> 
			<?php echo CONST_AF_SEARCH_BY_CHAR_METHOD?>
			<input type="radio" name="rad_filter" class="normal_radiobutton" value="0" <?php if ($v_method == 0) echo 'checked';?> onclick="document.forms(0).hdn_method.value = 0;">
			<?php echo CONST_AF_SEARCH_BY_WORDS_METHOD?>
		</td>
		<td  colspan="2"class="normal_label"><?php echo CONST_AF_LIST_FILTER_LABEL;?>
			<input type="text" class="normal_textbox" size="20" name="txt_filter_value" value="<?php echo $v_filter; ?>" onKeyDown="txt_filter_keydown()">
			<input type="button" class="small_button" style="width:28%" name="btn_filter" value="<?php echo _CONST_QUERY_DATA_BUTTON; ?>" onClick="filter_onclick('<? echo $fuseaction;?>');">
		</td>
	</tr>
	<tr><td colspan="4" height="5"></td></tr>
	<tr>
		<td class="normal_label" colspan="4" align="right">
		</td>
	</tr>
	<tr><td width="16%" height="10pt"></td></tr>
</table>
<!-- Bat cac phim: F12=false; Insert=true; Delete=true, ESC=false; Enter=false -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(false,true,true,false,false);">
<!--Bang noi dung chua cac thuat ngu-->
<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
	<col width="5%"><col width="10%"><col width="15%"><col width="50%"><col width="19%">
		<tr class="header">
		<td>#</td>
		<td><?php echo CONST_AF_ORDER_LABEL; ?></td>
		<td><?php echo CONST_AF_CODE_LABEL; ?></td>
		<td><?php echo CONST_AF_NAME_LABEL; ?></td>
		<td><?php echo _CONST_STATUS_COLUMN_HEADER; ?></td>
	</tr>
</table>	
<div style="overflow: auto; width: 100%; height:<?php echo _CONST_HEIGHT_OF_LIST?>;padding-left:0px;margin:0px">
<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
	<col width="5%"><col width="10%"><col width="15%"><col width="50%"><col width="19%">
	<?php 
	$v_count = sizeof($arr_all_af); 
	if ($v_count>0){
		for($row_index = 0;$row_index< $v_count ;$row_index++){
			$v_af_id = $arr_all_af[$row_index]['0'];
			$v_af_code = $arr_all_af[$row_index]['1'];
			$v_af_name = $arr_all_af[$row_index]['2'];
			$v_order = $arr_all_af[$row_index]['3'];
			$v_status =$arr_all_af[$row_index]['4'];
			if ($v_status==1){$v_status=CONST_AF_STATUS_APPROVE; }
			else if ($v_status==2){$v_status=CONST_AF_STATUS_APPROVED; }
			else if ($v_status==3){$v_status=CONST_AF_STATUS_REFUSE;}
			$v_url = "row_onclick(" . "document.forms(0).hdn_af_id"  .  ",'" . $v_af_id . "'," . "'DISPLAY_SINGLE_AF','" . $v_goto_url . "')";
			if ($v_current_style_name == "odd_row"){
				$v_current_style_name = "round_row";
			}else{
				$v_current_style_name = "odd_row";
			}?>	
			<tr class="<?php echo $v_current_style_name ?>"> 
				<td align="center">
					<input type="checkbox" name="chk_af_id" value="<?php echo $v_af_id; ?>">
				</td>
				<td align="center" onClick="<?php echo $v_url;?>">
					<a name="<?php echo $v_af_id;?>"><?php echo $v_order;?></a>
				</td>	
				<td align="left" onClick="<?php echo $v_url;?>">
					<a name="<?php echo $v_af_id;?>"><?php echo $v_af_code;?></a>
				</td>	
				<td align="left" onClick="<?php echo $v_url;?>">
					<a name="<?php echo $v_af_id;?>"><?php echo $v_af_name;?></a>
				</td>	
				<td align="center" onclick="<?php echo $v_url ;?>">
					<a name="<?php echo $v_af_id;?>"><?php echo $v_status; ?></a>
				</td>
			</tr><?php 
		}	
	}
	if ($v_current_style_name == "odd_row"){
		$v_next_style_name = "round_row";
	}else{
		$v_next_style_name = "odd_row";
	}
	echo _add_empty_row($v_count,_CONST_NUMBER_OF_ROW_PER_LIST,$v_current_style_name,$v_next_style_name,5);
	?>
</table>
</div><?php 
if ($v_count > 0){?>
	<table width="100%">
		<col width="50%"><col width="50%">
		<tr><td height="5pt"></td></tr>
		<tr>
			<td align="left" class="normal_label"><?php echo CONST_NUMBER_AF_LABEL."&nbsp;";?><small class="normal_starmark"><?php echo $v_count;echo "&nbsp;"?></small><?php echo CONST_NUMBER_AF_LABEL2;?></td>
			<td align="right" class="normal_label"><?php echo CONST_AF_SEE_DETAIL_LABEL;?></td>
		</tr>
	</table><?php
}?>
<!--Table chua cac button-->
<table align="center">
	<tr>
		<td></td>
	</tr>
	<tr>
		<td ><?php			
			if ($v_is_granted_update){?>
				<input type="button" value="<?php echo _CONST_ADD_BUTTON; ?>" name="btn_add" class="normal_button" onClick="btn_add_af_onclick(document.forms(0).hdn_af_id, 'DISPLAY_SINGLE_AF','<?php echo $v_goto_url; ?>')"><?php
			}	
			if ($v_is_granted_delete){?>
				<input type="button" value="<?php echo _CONST_DELETE_BUTTON; ?>" name="btn_delete" class="normal_button" onClick="btn_delete_onclick(document.forms(0).chk_af_id,document.forms(0).hdn_list_af_id,'DELETE_AF')"><?php
			}
			if ($v_is_granted_approve){?>
				<input type="button" value="<?php echo _CONST_APPROVE_BUTTON; ?>" name="btn_approve" class="normal_button" onClick="btn_approve_af_onclick('DISPLAY_SINGLE_APROVE_AF','<?php echo $v_goto_url; ?>')"><?php
			}?>	
		</td>
	</tr>
</table>
</div id="hotkey">
</form>
<script>
	document.all.goto.href="#<? echo $v_current_af_id;?>";
	document.all.goto.click();
</script>